package com.wt.admin.service.ai.impl.agents;

import com.wt.admin.domain.dto.ai.AgentsInfoDTO;
import com.wt.admin.domain.entity.ai.MCPEntity;
import com.wt.admin.domain.entity.ai.ModelConfigEntity;
import io.micrometer.observation.ObservationRegistry;
import org.springframework.ai.model.tool.ToolCallingManager;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.ai.ollama.management.ModelManagementOptions;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("Ollama")
public class OllamaBuilder extends AbstractAgentsBuilderService{

    @Override
    public AgentsManager.ChatClientMapper builder(AgentsInfoDTO agents, ModelConfigEntity model, List<MCPEntity> mcpEntities) {
        // 查询模型信息
        var ollamaApi = OllamaApi.builder().
                baseUrl(model.getBaseUrl())
                .build();
        OllamaOptions options = OllamaOptions.builder()
                .model(model.getModel()).temperature(0.7).build();
        OllamaChatModel ollama = new OllamaChatModel(
                ollamaApi ,
                options,
                ToolCallingManager.builder().build(),
                ObservationRegistry.NOOP,
                ModelManagementOptions.defaults()
        );
        // 在构建完模型后，对模型做其他初始化
        return build(ollama, agents, mcpEntities,options);
    }

}
